package com.noocodecommit.wicket.jquery.plugin.ui.dialog;

import org.apache.wicket.ajax.AjaxRequestTarget;

import com.noocodecommit.wicket.jquery.TemplatePage;
import com.noocodecommit.wicket.stuff.jquery.JQCore;
import com.noocodecommit.wicket.stuff.jquery.plugin.chili.JQChili;
import com.noocodecommit.wicket.stuff.jquery.plugin.ui.dialog.JQDialog;
import com.noocodecommit.wicket.stuff.jquery.plugin.ui.dialog.JQDialogUtils;
import com.noocodecommit.wicket.stuff.jquery.plugin.ui.dialog.OnDialogButtonClickedBehavior;
import com.noocodecommit.wicket.stuff.jquery.plugin.ui.dialog.OnDialogCloseBehavior;
import com.noocodecommit.wicket.stuff.jquery.plugin.ui.dialog.OnDialogOpenBehavior;
import com.noocodecommit.wicket.stuff.jquery.plugin.ui.tabs.JQTabs;

public class DialogPage extends TemplatePage
{

	private static final long serialVersionUID = 1L;
	private final JQTabs tabContainer;

	public DialogPage()
	{
		super();
		JQCore.init(this);
		this.setupChili();

		tabContainer = new JQTabs("tab-container");
		tabContainer.setOutputMarkupId(true);
		add(tabContainer);

		/*************************************************************************************************************************************************************************************************************************************************
		 * Simple Dialog
		 ************************************************************************************************************************************************************************************************************************************************/
		JQDialog dialog1 = JQDialogUtils.create("dialog1").title("title").addButton("ok", "alert('button click alert');").build();
		tabContainer.add(dialog1);
		dialog1.add(new OnDialogButtonClickedBehavior("ok")
		{
			public void onClick(AjaxRequestTarget target)
			{
				target.appendJavascript("alert('button click ajax behavior alert')");

			}
		});

		dialog1.add(new OnDialogOpenBehavior()
		{
			public void onOpen(AjaxRequestTarget target)
			{
				target.appendJavascript("alert('dialog opened')");
			}
		});

		dialog1.add(new OnDialogCloseBehavior()
		{
			public void onClose(AjaxRequestTarget target)
			{
				target.appendJavascript("alert('dialog closed')");
			}
		});

		JQChili chili1 = new JQChili("chili1");
		add(chili1);
		this.bindChiliCode(chili1, this.getClass(), "html");

		JQChili chili2 = new JQChili("chili2");
		add(chili2);
		this.bindChiliCode(chili2, this.getClass(), "java");

		JQCore.get().bindOnDocumentReadyFunction();
	}
}
